package cn.edu.Utils;

import cn.edu.dao.EmployeeMapper;
import cn.edu.pojo.Employee;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author wans
 * @create 2022-09-22 20:19
 */
public class MybatisUtils {
    public static SqlSession getConnection(){
        String resources="mybatis-config.xml";
        Reader reader=null;
        SqlSession session=null;
        try {
            reader = Resources.getResourceAsReader(resources);
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
            session = factory.openSession();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            return session;
        }
    }
}
